package validatorx

import (
	"time"

	"github.com/go-playground/validator/v10"
)

var validate *validator.Validate

func init() {
	validate = validator.New()

	if err := validate.RegisterValidation("day", CheckDay); err != nil {
		panic(err)
	}
}

func Struct(s interface{}) error {
	return validate.Struct(s)
}

// CheckDay 校验日期格式
func CheckDay(f validator.FieldLevel) bool {
	_, err := time.ParseInLocation("2006-01-02", f.Field().String(), time.Local)
	if err != nil {
		return false
	}

	return true
}
